//
//  ThingsViewController.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 16/9/7.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "ThingsViewController.h"
#import "BusinessMenuViewController.h"
#import "MyButtonMainPage.h"
#import "SetUPViewController.h"
#import "ZCZBarViewController.h"
#import "ZJLoopScrollView.h"
#import "PersonalMissionViewController.h"
#import "MessageAlertViewController.h"
#import "TabBarOccupyingController1.h"
#import "ListsViewController.h"
#import "MJRefresh.h"
#import "JPUSHService.h"
#import "WebViewController.h"
//#import "ThingsCollectionViewCell.h"
#import "NewMenuLeftCell.h"
#import "MenuRightCell.h"
#import "MenuModel.h"
#import "MenuCellWithSty.h"
#import "TimeLineViewController.h"
#import "EvaluateViewController.h"
#import "ClassContentController.h"

#define TimeLine 4//第五个是有时间轴的
#define Evaluate 6//第七个是评价
#define ClassContent 0xabbba//暂时隐藏      //第四个是课堂内容
#define NeedDownload 4//第五个需要下载       //没有用了
#define show_star 0xaabbcce//暂时隐藏       //第九个
#define parent_meet 0xaabbeee//暂时隐藏     //第十个



#define STYLE0 @"0" // 主项目风格
#define STYLE1 @"1" // 学员端风格

@interface ThingsViewController ()
{
    
    ZJLoopScrollView *loopView;
    
    UITableView *leftTableView;//左菜单
    UITableView *rightTableView;//右菜单
    
}

//@property(nonatomic,retain)NSDictionary *dic2;
@property(nonatomic,retain)NSMutableArray *menuArr;
@property(nonatomic,retain)NSMutableArray *nineArr;
@property(nonatomic,retain)NSMutableArray *secondArr;
@property(nonatomic,assign)BOOL isheng;
@property(nonatomic,retain)NSMutableArray *rightItemsArr;
@property(nonatomic,retain)NSArray *imageArr;
@property(nonatomic,retain)NSMutableArray *nextMutArr;
@property(nonatomic,strong)NSDictionary *tableImg;
@property(nonatomic,assign)BOOL isMeeting;
@property(nonatomic,strong)NSMutableArray *IconCountBeginArr;//图片的开始值
@property(nonatomic,strong)NSIndexPath *leftIndexPath;//左侧tabelview的indexpath
@end

@implementation ThingsViewController

-(void)viewWillAppear:(BOOL)animated{
    NSLog(@"123");
    NSLog(@"123");
    NSLog(@"123");
    NSLog(@"123");

    [super viewWillAppear:animated];
    self.cusTabView.hidden = NO;
    
    if([getUIStyle() isEqualToString:STYLE0]){
      
        if (_red) {
            NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
            NSString *badge = [ud objectForKey:@"badge"];
            if (badge.integerValue>0) {
                _red.hidden = NO;
            }else{
                _red.hidden = YES;
            }
        }
        if(_menuArr.count==0){
            [self getDocumentData];
        }

    }else{
        if (_red) {
            NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
            NSString *badge = [ud objectForKey:@"badge"];
            if (badge.integerValue>0) {
                _red.hidden = NO;
            }else{
                _red.hidden = YES;
            }
        }
        if(_menuArr.count==0){
            [self getDocumentData];
        }

    }
    

}



-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.sasa
    _rightItemsArr =[[NSMutableArray alloc]init];
    _nextMutArr =[[NSMutableArray alloc]init];
    
       if([getUIStyle() isEqualToString:STYLE0]){
           [self setTitleLabelText:@"功能管理"];
    NSLog(@"主项目程序");
    [self newCreatUI];
    self.view.backgroundColor =[UIColor colorWithHex:0xf5f8fa];
       }else{
           [self setTitleLabelText:@"分类"];
           [self createUI];
           self.view.backgroundColor =[UIColor colorWithHex:0xffffff];
       }

  
    self.dataArr = [[NSMutableArray alloc]init];
    self.nineArr =[[NSMutableArray alloc]init];
    _imageArr = @[@"stu_my_order",@"stu_my_task",@"stu_my_journal",@"stu_my_attendance",@"stu_my_leave",@"stu_my_visit",@"stu_my_achievement",@"stu_my_evaluate",@"stu_my_evaluate_curriculum"];

    

    [self getDocumentData];
    
}

-(UIView *)red{
    if (!_red) {
        _red = [[UIView alloc] init];
        _red.backgroundColor = [UIColor redColor];
        _red.layer.cornerRadius = 2.6f;
        
    }
    return _red;
}

-(UIButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = [[UIButton alloc] init];
        
    }
    return _rightBtn;
}


#pragma mark - 事物看板内容获取
-(void)getDocumentData{
    //    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *filename=getSaveFile(userName(),LOGINFOUNCTION);   //获取路径
    NSString *path=[filename stringByAppendingPathComponent:LOGINOK];
    
    NSData *dataNow = [NSData dataWithContentsOfFile:path];
    NSDictionary * dic;
    if(dataNow){
        
        dic = [NSJSONSerialization JSONObjectWithData:dataNow options:NSJSONReadingMutableContainers error:nil];  //读取数据
    }

//    NSLog(@"%@",dic);
    _dic2 = dic;
    
     if([getUIStyle() isEqualToString:STYLE0]){
            [self newMenuMainDataUse];
     }else{
            [self menuStuDataUse];
     }

    
//    NSLog(@"dic2 is:%@",_dic2);
}

#pragma mark - 代码分支 --- 栏目主项目数据处理代码
//主项目执行的

-(void)newMenuMainDataUse{
    NSMutableArray *arr  =[_dic2 objectForKey:@"menuList"];

    NSLog(@"主项目程序");

//    NSMutableArray *arrd = [[NSMutableArray alloc]init];
    
    NSLog(@"%lu",(unsigned long)_menuArr.count);
    
    for (NSDictionary *dic in arr) {
        MenuModel *model = [[MenuModel alloc]init];
        model = [model initWithDictionary:dic error:nil];
        
        
        if(model.meunColl&&model.meunColl.count>0){
            
                        NSMutableArray *arrM = [[NSMutableArray alloc]init];
                        
                        for (NSDictionary *dicM in model.meunColl) {
                            MenuModel *modelM = [[MenuModel alloc]init];
                            modelM = [modelM initWithDictionary:dicM error:nil];
                            
                                        if(modelM.meunColl&&modelM.meunColl.count>0){
                                            
                                            NSMutableArray *arrL = [[NSMutableArray alloc]init];

                                            for (NSDictionary *dicL in modelM.meunColl) {
//                                                MenuModel *modelL = [[MenuModel alloc]init];
                                                //modelL = [modelL initWithDictionary:dicL error:nil];
                                                
                                                [arrL addObject:modelM];

                                            }
                                            
                                            modelM.meunColl = arrL;
                                            
                                        }
                            [arrM addObject:modelM];
                        }
            
            
                        model.meunColl = arrM;
            
        }
      
        if(model.meunColl.count == 0){
            
            model.meunColl = [NSArray arrayWithObject:model];
            
        }
        [_menuArr addObject:model];
    }
    
    [leftTableView reloadData];
    
    _IconCountBeginArr = [[NSMutableArray alloc] init];
    NSInteger count = 0;
    [_IconCountBeginArr addObject:@"0"];
    for (MenuModel *model in _menuArr) {
         count += model.meunColl.count;
        [_IconCountBeginArr addObject:[NSString stringWithFormat:@"%li",(long)count]];
    }
    
    
    
    
    if(_menuArr.count>0){
        NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];
        [leftTableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom];
        NSIndexPath *path=[NSIndexPath indexPathForItem:0 inSection:0];
        [self tableView:leftTableView didSelectRowAtIndexPath:path];
    }

}

#pragma mark - 代码分支 --- 事务看板学员端数据处理代码 ---------- 栏目学员风格
-(void)menuStuDataUse{
    
    //    NSString *parentIdSave = @"";
    NSMutableArray *arr  =[_dic2 objectForKey:@"menuList"];
    NSMutableArray *arr1  =[_dic2 objectForKey:@"menuList"];
    
    for(NSDictionary *dic in arr){
        NSString *str =[NSString stringWithFormat:@"%@", [dic objectForKey:@"parent_menuId"]];
        BOOL is = YES; // 是没有 问题的 是否是父级
        
        for (NSDictionary *dic1 in arr1) {
            NSString *str1 = [NSString stringWithFormat:@"%@", [dic1 objectForKey:@"menuId"]];
            
            if ([str isEqualToString:str1]) {
                
                is = NO;
                
                continue;
            }
        }
        
        if (is) { // 是否是父级
            
            
            [_menuArr addObject:dic];
            //                break;
        }else{
            [_secondArr addObject:dic];
        }
    }
    
//    NSDictionary *lastDic = @{@"img":@"椭圆-1-拷贝-2"};
//    [_menuArr addObject:lastDic];
    NSLog(@"%lu",(unsigned long)_menuArr.count);
//    _nineArr =_menuArr;

}

-(void)menuDataUse{
    
    NSMutableArray *arr  =[_dic2 objectForKey:@"roleFollowList"];
    [self.dataArr removeAllObjects];
    [self.collectionView.header endRefreshing];
    for (NSDictionary *dic in arr) {
        ThingsModel *model = [[ThingsModel alloc]init];
        model = [model initWithDictionary:dic error:nil];
        [self.dataArr addObject:model];
    }
    [self.collectionView reloadData];
}
//主项目执行的UI
-(void)newCreatUI{
    _menuArr = [[NSMutableArray alloc]init];
    _secondArr = [[NSMutableArray alloc]init];
    
    
    UILabel *menuLa =[[UILabel alloc]init];
    [self.view addSubview:menuLa];
    [menuLa mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(28);
        make.top.equalTo(self.view.mas_top).offset(11);
    }];
    menuLa.text = @"功能菜单";
    menuLa.textColor =[UIColor colorWithHex:0x7c8084];
    menuLa.font =[UIFont systemFontOfSize:17];
    
    UIView *l1 =[[UIView alloc]init];
    [self.view addSubview:l1];
    [l1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(menuLa.mas_bottom).offset(11);
        make.height.equalTo(@(0.5));
        make.width.equalTo(@(124));
    }];
    l1.backgroundColor =[UIColor colorWithHex:0xcbcbcb];
    
    leftTableView =[[UITableView alloc]init];
    [self.view addSubview:leftTableView];
    leftTableView.dataSource = self;
    leftTableView.delegate = self;
    [leftTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(l1.mas_bottom);
        make.width.equalTo(@(248/2));
        make.bottom.equalTo(self.view.mas_bottom).offset(-49);
    }];
    leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    leftTableView.bounces = NO;
    
    
    UIView *l2 =[[UIView alloc]init];
    [self.view addSubview:l2];
    [l2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftTableView.mas_right);
        make.top.equalTo(leftTableView.mas_top);
        make.bottom.equalTo(leftTableView.mas_bottom);
        make.width.equalTo(@(0.5));
    }];
    l2.backgroundColor =[UIColor colorWithHex:0xcbcbcb];
    
    NSInteger selectedIndex = 0;
    NSIndexPath *selectedIndexPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
    [leftTableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    [flowLayout setItemSize:CGSizeMake(([UIScreen mainScreen].bounds.size.width-133-9-9)/2, 188/2)];//设置cell的尺寸
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置其边界
    flowLayout.minimumInteritemSpacing = 0;
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(130, 0, [UIScreen mainScreen].bounds.size.width-130, [UIScreen mainScreen].bounds.size.height-64) collectionViewLayout:flowLayout];
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(12);
        make.left.equalTo(leftTableView.mas_right).offset(9);
        make.right.equalTo(self.view.mas_right).offset(-9);
        make.bottom.equalTo(self.view.mas_bottom).offset(-64);
    }];
    
    self.collectionView.backgroundColor = [UIColor clearColor];

    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[ThingsCollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];//注册必不可少

}

//#ifdef Main

//修改collectionView的行间距 全局
//#pragma mark - collectionView ******主项目*******修改行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    
    if([getUIStyle() isEqualToString:STYLE0]){
        return 9;
    }else{
        return 0;
    }
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    if(tableView==leftTableView){
    return [_menuArr count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 110/2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


        static NSString *str = @"identifier";
//     NSDictionary *dic = [_menuArr objectAtIndex:indexPath.row];
        
        MenuModel *model = [_menuArr objectAtIndex:indexPath.row];

    NewMenuLeftCell *cell =[tableView dequeueReusableCellWithIdentifier:str];
        
    if(cell==nil){
        cell =[[NewMenuLeftCell alloc]initWithReuseIdentifier:str];
    }
//        NSMutableString *strMenuName = [NSMutableString stringWithFormat:@"%@", [dic objectForKey:@"menuName"]];
    NSLog(@"%@", model.menuName);
        NSMutableString *strMenuName = [NSMutableString stringWithFormat:@"%@", model.menuName];

        if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
            [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
        }
        cell.selectedBackgroundView=[[UIView alloc]initWithFrame:cell.frame];
        cell.selectedBackgroundView.backgroundColor=[UIColor clearColor];
    cell.menuLabel.text = strMenuName;
        int i = arc4random() % 8+1;
        cell.img.image =[UIImage imageNamed:[NSString stringWithFormat:@"a%d",i]];
        cell.img.highlightedImage = [UIImage imageNamed:[NSString stringWithFormat:@"a%d_%d",i,i]];
    return cell;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //if(tableView==leftTableView){
    //NSDictionary *dic = [_menuArr objectAtIndex:indexPath.row];
    _leftIndexPath = indexPath;
    MenuModel *model = [_menuArr objectAtIndex:indexPath.row];
    NewMenuLeftCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.LIne.backgroundColor =[UIColor colorWithHex:0xe6e6e6];
    
    _rightItemsArr = (NSMutableArray *)model.meunColl;
    
    [self.collectionView reloadData];
        
        
//            }else{
//        return;

}


//学员端执行的UI
-(void)createUI{

    _menuArr = [[NSMutableArray alloc]init];
    _secondArr = [[NSMutableArray alloc]init];
    
    
    if([getUIStyle() isEqualToString:STYLE0]){
    }else{
        UIButton *leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        leftNavBtn.frame = CGRectMake(0, 0, 44/2, 44/2);
        //形状-16@2x
        leftNavBtn.hidden = YES;//隐藏扫码
        [leftNavBtn setBackgroundImage:[UIImage imageNamed:@"nav_scan_code"] forState:UIControlStateNormal];
        [leftNavBtn addTarget:self action:@selector(LeftClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:leftNavBtn];
        self.navigationItem.leftBarButtonItem = item;
        
        self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.rightBtn.frame = CGRectMake(0, 0, 44/2, 44/2);
        //
        [self.rightBtn setBackgroundImage:[UIImage imageNamed:@"nav_news"] forState:UIControlStateNormal];
        [self.rightBtn addTarget:self action:@selector(RightClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *ritem = [[UIBarButtonItem alloc]initWithCustomView:self.rightBtn];
        self.navigationItem.rightBarButtonItem = ritem;
        
        NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
        NSString *badge = [ud objectForKey:@"badge"];
        NSLog(@"%zd",badge.integerValue);
        
        if (badge.integerValue>0) {
            NSLog(@"有未读消息");
            [self.rightBtn addSubview:self.red];
            [self.red mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.rightBtn.mas_top);
                make.right.equalTo(self.rightBtn.mas_right).offset(2.5);
                make.width.equalTo(@(5));
                make.height.equalTo(@(5));
            }];
        }else{
            NSLog(@"无未读消息");
            
        }
  
    }

    
    if([getUIStyle() isEqualToString:STYLE0]){
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    [flowLayout setItemSize:CGSizeMake([UIScreen mainScreen].bounds.size.width/4, 230/2)];//设置cell的尺寸
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置其边界
    flowLayout.minimumInteritemSpacing = 0;
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) collectionViewLayout:flowLayout];
    }else{
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        [flowLayout setItemSize:CGSizeMake([UIScreen mainScreen].bounds.size.width/3, 278/2)];//设置cell的尺寸
        [flowLayout setMinimumLineSpacing:0];
        [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//设置其布局方向
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);//设置其边界
        flowLayout.minimumInteritemSpacing = 0;
        self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) collectionViewLayout:flowLayout];
    }
   
    
    //其布局很有意思，当你的cell设置大小后，一行多少个cell，由cell的宽度决定
    
    
    
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);//.offset(-64);
    }];
    
    self.collectionView.backgroundColor = [UIColor clearColor];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[ThingsCollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];//注册必不可少

}
- (void)LeftClick:(UIButton *)sender{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusDenied||authStatus == AVAuthorizationStatusRestricted) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请允许该应用使用相机\n方法：设置->隐私->相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [alert show];
            return ;
        }
    }
    
    ZCZBarViewController *zvc = [[ZCZBarViewController alloc] initWithBlock:^(NSString * data, BOOL succeed) {
        if(succeed){
            NSString *urlStr = [[NSString alloc]initWithString:data];
            NSLog(@"%@", urlStr);
            
            [NetRequest requestUrl:urlStr andParamas:nil andReturnBlock:^(NSData *data, NSError *error) {
                if(!error&&data!=nil){
                    NSString *str = [[NSString alloc]initWithData:data  encoding:NSUTF8StringEncoding];
                    NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                    NSLog(@"%@", obj);
                    if ([str isEqualToString:@"1"]) {
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:@"考勤成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        alert.delegate = self;
                        [alert show];
                    }else{
                        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                        alert.delegate = self;
                        [alert show];
                    }
                    NSLog(@"sucess!");
//                    _sucess = YES;
                }else{
                    
                    NSString *str = [NSString stringWithFormat:@"系统错误！%@",urlStr];
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"考勤" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    alert.delegate = self;
                    [alert show];
                    NSLog(@"%@",error);
//                    _sucess = NO;
                }
                
            }];
            //            NSLog(@"%@",erro);
            
        }
        
    }];
    
    [self.navigationController presentViewController:zvc animated:YES completion:^{
        
    }];;
}
- (void)RightClick:(UIButton *)sender{
    MessageAlertViewController *mavc = [[MessageAlertViewController alloc] init];
    mavc.tabbarView = self.cusTabView;
    [self.navigationController pushViewController:mavc animated:YES];
}
#pragma mark - collectionView dataSource Or delegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

      if([getUIStyle() isEqualToString:STYLE0]){
          return [_rightItemsArr count];
      }else{
        return _menuArr.count;
      }

}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    MenuCellWithSty *styleCell = [[MenuCellWithSty alloc]init];
    

     if([getUIStyle() isEqualToString:STYLE0]){
         MenuModel *model = [_rightItemsArr objectAtIndex:indexPath.row];
         if (_IconCountBeginArr.count>_leftIndexPath.row&&_leftIndexPath!=nil) {
             NSInteger beginCount = [[_IconCountBeginArr objectAtIndex:_leftIndexPath.row] integerValue];
             
             return [styleCell UIStyle:STYLE0 andCollectionView:collectionView withIndexPath:indexPath andModel:model withNum:beginCount];
         }
         return [styleCell UIStyle:STYLE0 andCollectionView:collectionView withIndexPath:indexPath andModel:model withNum:_rightItemsArr.count];

     }else{
         NSDictionary *dic = [_menuArr objectAtIndex:indexPath.row];
         
         return [styleCell UIStyle:STYLE1 andCollectionView:collectionView withIndexPath:indexPath andModel:dic withNum:_rightItemsArr.count];
         
     }

    
    
    


    
}

-(void)seleCollectionCellWithIndexPath:(NSIndexPath *)indexPath{
    
    MenuModel *model = [_rightItemsArr objectAtIndex:indexPath.row];
    
    
    //NSMutableArray *nextArr = [[NSMutableArray alloc]init];
    NSLog(@"---->==|%@|==<-----",_secondArr);
    
    NSString *classListStr = [NSString stringWithFormat:@"%@", model.menuPageUrl];
    
    if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
        TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
        
        self.cusTabView.hidden = YES;
        
        //            tbOC.dataDic = dic;
        
        tbOC.model = model;
        
        tbOC.fromPop = YES;
        [self.navigationController pushViewController:tbOC animated:YES];
        return;
    }
    
    ListsViewController *lv =[[ListsViewController alloc]init];

    lv.pageId = model.pageId; //[oneDic valueForKey:@"pageId"];
    lv.tableId = model.tableId; //[oneDic valueForKey:@"tableId"];

    
    lv.cusTabView = self.cusTabView;
    
    [self.navigationController pushViewController:lv animated:YES];
    
    //    }

}

#pragma mark - 学员端风格 相应事件
-(void)seleStyle1CCell:(NSIndexPath *)indexPath{
    if(indexPath.row==_menuArr.count){
        
        return;
    }
    
    
    
    
    NSDictionary *dic = [_menuArr objectAtIndex:indexPath.row];
    NSMutableArray *nextArr = [[NSMutableArray alloc]init];
    NSString *anyWay = [NSString stringWithFormat:@"%@",[dic objectForKey:@"actionWay"]];
    
    if([anyWay isEqualToString:@"1"]||[dic objectForKey:@"menuPageUrl"]){
        WebViewController *web =[[WebViewController alloc]init];
        web.cusTabView = self.cusTabView;
        [self.navigationController pushViewController:web animated:YES];
        web.menu_Url = [NSString stringWithFormat:@"%@", [dic objectForKey:@"menuPageUrl"]];
        
    }else{
        if([dic valueForKey:@"meunColl"]){
            
            nextArr= [[NSMutableArray alloc]initWithArray:[dic valueForKey:@"meunColl"]];
        }else{
            [nextArr addObject:dic];
        }
        
        //*** pop Which View
        if(nextArr.count>0){
            
            if([getUIStyle() isEqualToString:STYLE0]){
                BusinessMenuViewController *nv =[[BusinessMenuViewController alloc]init];
                nv.titleString = [dic objectForKey:@"menuName"];
                
                [self.navigationController pushViewController:nv animated:YES];
                nv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                nv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                
                nv.menu_url = [_dic2 objectForKey:@"timeInterface"];
                nv.cusTabView = self.cusTabView;
            }else{
                NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
                if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
                    TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
                    
                    self.cusTabView.hidden = YES;
                    
                    tbOC.dataDic = dic;
                    tbOC.fromPop = YES;
                    [self.navigationController pushViewController:tbOC animated:YES];
                    return;
                }
                
                //这里添加功能判断
                if (getTimeLineModel()) {
                    
                    //            if ([getUserType() isEqualToString:UserISHPSStudent]) {
                    if (indexPath.row == TimeLine&&getTimeLineModel()) {
                        NSLog(@"有时间轴");
                        TimeLineViewController *tl =[[TimeLineViewController alloc]init];
                        tl.isTimeLine = YES;
                        NSDictionary *oneDic =[nextArr objectAtIndex:0];
                        
                        NSDictionary *menuDic = [_menuArr objectAtIndex:indexPath.row];
                        if ([menuDic objectForKey:@"menuName"]) {
                            tl.menuName = [menuDic objectForKey:@"menuName"];
                        }
                        tl.pageId = [oneDic valueForKey:@"pageId"];
                        tl.tableId = [oneDic valueForKey:@"tableId"];
                        
                        tl.cusTabView = self.cusTabView;
                        tl.menu_url =[_dic2 objectForKey:@"timeInterface"];
                        tl.allArr = [NSMutableArray arrayWithArray:_secondArr];
                        tl.secondArr = [NSMutableArray arrayWithArray:nextArr];
                        
                        
                        
                        [self.navigationController pushViewController:tl animated:YES];
                    }else if(indexPath.row == parent_meet){
                        NSLog(@"家长会");
                        
                        ListsViewController *lv =[[ListsViewController alloc]init];
                        lv.isTimeLine = NO;
                        NSDictionary *oneDic =[nextArr objectAtIndex:0];
                        
                        if(indexPath.row == show_star){
                            lv.isNine=YES;
                        }else{
                            lv.isNine=NO;
                        }
                        NSDictionary *menuDic = [_menuArr objectAtIndex:indexPath.row];
                        if ([menuDic objectForKey:@"menuName"]) {
                            lv.menuName = [menuDic objectForKey:@"menuName"];
                        }
                        lv.pageId = [oneDic valueForKey:@"pageId"];
                        lv.tableId = [oneDic valueForKey:@"tableId"];
                        
                        lv.cusTabView = self.cusTabView;
                        lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                        lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                        lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                        if (indexPath.row == parent_meet) {
                            lv.isNeedDownload = YES;
                            lv.isMeeting = YES;
                        }else{
                            lv.isNeedDownload = NO;
                            lv.isMeeting = NO;
                        }
                        
                        
                        [self.navigationController pushViewController:lv animated:YES];
                        
                    }else if(indexPath.row == Evaluate&&getEvalutionModel()){
                        
                        NSLog(@"评价");
                        EvaluateViewController *evaView =[[EvaluateViewController alloc]init];
                        evaView.isTimeLine = NO;
                        
                        NSDictionary *oneDic =[nextArr objectAtIndex:0];
                        
                        NSDictionary *menuDic = [_menuArr objectAtIndex:indexPath.row];
                        if ([menuDic objectForKey:@"menuName"]) {
                            evaView.menuName = [menuDic objectForKey:@"menuName"];
                        }
                        
                        evaView.pageId = [oneDic valueForKey:@"pageId"];
                        evaView.tableId = [oneDic valueForKey:@"tableId"];
                        
                        evaView.cusTabView = self.cusTabView;
                        evaView.menu_url =[_dic2 objectForKey:@"timeInterface"];
                        evaView.allArr = [NSMutableArray arrayWithArray:_secondArr];
                        evaView.secondArr = [NSMutableArray arrayWithArray:nextArr];
                        
                        
                        
                        [self.navigationController pushViewController:evaView animated:YES];
                    }else if (indexPath.row == ClassContent){
                        ClassContentController *classv =[[ClassContentController alloc]init];
                        NSDictionary *oneDic =[nextArr objectAtIndex:0];
                        
                        classv.pageId = [oneDic valueForKey:@"pageId"];
                        classv.tableId = [oneDic valueForKey:@"tableId"];
                        NSDictionary *menuDic = [_menuArr objectAtIndex:indexPath.row];
                        if ([menuDic objectForKey:@"menuName"]) {
                            classv.menuName = [menuDic objectForKey:@"menuName"];
                        }
                        classv.cusTabView = self.cusTabView;
                        classv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                        classv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                        classv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                        [self.navigationController pushViewController:classv animated:YES];
                        
                    }else{
                        NSLog(@"bbb");
                        ListsViewController *lv =[[ListsViewController alloc]init];
                        lv.isTimeLine = NO;
                        NSDictionary *oneDic =[nextArr objectAtIndex:0];
                        
                        if(indexPath.row == show_star){
                            lv.isNine=YES;
                        }else{
                            lv.isNine=NO;
                        }
                        NSDictionary *menuDic = [_menuArr objectAtIndex:indexPath.row];
                        if ([menuDic objectForKey:@"menuName"]) {
                            lv.menuName = [menuDic objectForKey:@"menuName"];
                        }
                        lv.pageId = [oneDic valueForKey:@"pageId"];
                        lv.tableId = [oneDic valueForKey:@"tableId"];
                        
                        lv.cusTabView = self.cusTabView;
                        lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                        lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                        lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                        if (indexPath.row == NeedDownload) {
                            lv.isNeedDownload = YES;
                        }else{
                            lv.isNeedDownload = NO;
                        }
                        
                        
                        [self.navigationController pushViewController:lv animated:YES];
                    }
                    
                    
                    
                    
                }else{
                    NSLog(@"bbb");
                    ListsViewController *lv =[[ListsViewController alloc]init];
                    lv.isTimeLine = NO;
                    NSDictionary *oneDic =[nextArr objectAtIndex:0];
                    NSDictionary *menuDic = [_menuArr objectAtIndex:indexPath.row];
                    if ([menuDic objectForKey:@"menuName"]) {
                        lv.menuName = [menuDic objectForKey:@"menuName"];
                    }
                    lv.pageId = [oneDic valueForKey:@"pageId"];
                    lv.tableId = [oneDic valueForKey:@"tableId"];
                    
                    lv.cusTabView = self.cusTabView;
                    lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                    lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                    lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                    
                    
                    
                    [self.navigationController pushViewController:lv animated:YES];
                }
                
                
                
                
                
                
            }
            
            
            
        }else{
            
            NSString *classListStr = [NSString stringWithFormat:@"%@", [dic valueForKey:@"menuPageUrl"]];
            if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
                TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
                
                self.cusTabView.hidden = YES;
                
                tbOC.dataDic = dic;
                tbOC.fromPop = YES;
                [self.navigationController pushViewController:tbOC animated:YES];
                return;
            }
#pragma mark - 恢复代码  从测试使用到这里恢复
            //        ListsViewController *lv =[[ListsViewController alloc]init];
            //
            //        NSMutableString *menuName = [NSMutableString stringWithFormat:@"%@", [dic objectForKey:@"menuName"]];
            //        if ([menuName rangeOfString:@"手机端"].location != NSNotFound) {
            //            [menuName replaceCharactersInRange:[menuName rangeOfString:@"手机端"] withString:@""];
            //        }
            //
            //        if (menuName) {
            //            lv.menuName = menuName;
            //        }else{
            //            lv.menuName = @"列表";
            //        }
            //        lv.pageId = [dic valueForKey:@"pageId"];
            //        lv.tableId = [dic valueForKey:@"tableId"];
            //
            //        lv.cusTabView = self.cusTabView;
            //测试使用
            if (indexPath.row == TimeLine) {
                NSLog(@"有时间轴");
                TimeLineViewController *tl =[[TimeLineViewController alloc]init];
                tl.isTimeLine = YES;
                NSDictionary *oneDic =[nextArr objectAtIndex:0];
                
                
                tl.pageId = [oneDic valueForKey:@"pageId"];
                tl.tableId = [oneDic valueForKey:@"tableId"];
                
                tl.cusTabView = self.cusTabView;
                tl.menu_url =[_dic2 objectForKey:@"timeInterface"];
                tl.allArr = [NSMutableArray arrayWithArray:_secondArr];
                tl.secondArr = [NSMutableArray arrayWithArray:nextArr];
                
                
                
                [self.navigationController pushViewController:tl animated:YES];
            }else if(indexPath.row == Evaluate){
                NSLog(@"评价");
            }else{
                NSLog(@"bbb");
                ListsViewController *lv =[[ListsViewController alloc]init];
                lv.isTimeLine = NO;
                NSDictionary *oneDic =[nextArr objectAtIndex:0];
                
                
                lv.pageId = [oneDic valueForKey:@"pageId"];
                lv.tableId = [oneDic valueForKey:@"tableId"];
                
                lv.cusTabView = self.cusTabView;
                lv.menu_url =[_dic2 objectForKey:@"timeInterface"];
                lv.allArr = [NSMutableArray arrayWithArray:_secondArr];
                lv.secondArr = [NSMutableArray arrayWithArray:nextArr];
                
                
                
                [self.navigationController pushViewController:lv animated:YES];
            }
            
            
            
            
            
            
#pragma mark - 恢复代码这句也要打开
            //         [self.navigationController pushViewController:lv animated:YES];
            
        }
  
    }
    
    
}

#pragma mark - 主项目风格相应事件
-(void)seleStyle0CCell:(NSIndexPath *)indexPath{
    MenuModel *model = [_rightItemsArr objectAtIndex:indexPath.row];
    
    NSLog(@"---->==|%@|==<-----",_secondArr);
    
    NSString *anyWay = [NSString stringWithFormat:@"%@",model.actionWay];
    
    if([anyWay isEqualToString:@"1"]||model.menuPageUrl){
        WebViewController *web =[[WebViewController alloc]init];
        web.cusTabView = self.cusTabView;
        [self.navigationController pushViewController:web animated:YES];
        web.menu_Url = [NSString stringWithFormat:@"%@", model.menuPageUrl];
        return;
    }else{
        NSString *classListStr = [NSString stringWithFormat:@"%@", model.menuPageUrl];
        
        if ([classListStr rangeOfString:@"tableId="].location!=NSNotFound) {
            TabBarOccupyingController1 *tbOC = [[TabBarOccupyingController1 alloc]init];
            
            self.cusTabView.hidden = YES;
            
            
            
            tbOC.model = model;
            
            tbOC.fromPop = YES;
            [self.navigationController pushViewController:tbOC animated:YES];
            return;
        }
        if([model.menuName containsString:@"Teaching Evaluation"]){
            
            EvaluateViewController *evaView =[[EvaluateViewController alloc]init];
            evaView.isTimeLine = NO;
            
            //        NSDictionary *menuDic = [_menuArr objectAtIndex:indexPath.row];
            //        if ([menuDic objectForKey:@"menuName"]) {
            //            evaView.menuName = [menuDic objectForKey:@"menuName"];
            //        }
            
            evaView.pageId = model.pageId;
            evaView.tableId = model.tableId;
            
            evaView.cusTabView = self.cusTabView;
            evaView.allArr = [NSMutableArray arrayWithArray:_secondArr];
            evaView.menuName = model.menuName;
            
            
            
            [self.navigationController pushViewController:evaView animated:YES];
            
        }else{
            ListsViewController *lv =[[ListsViewController alloc]init];
            NSString *str = model.menuName;
            NSRange homeRange = [str rangeOfString:@"Assessment of 1on1 class"];
            if (homeRange.location != NSNotFound) {
                lv.TeacherNeedDownLoad = YES;
            }else{
                lv.TeacherNeedDownLoad = NO;
            }
            
            lv.pageId = model.pageId;
            lv.tableId = model.tableId;
            lv.menuName = model.menuName;
            lv.cusTabView = self.cusTabView;
            
            [self.navigationController pushViewController:lv animated:YES];
            
        }
  
    }
    
    
    

}
//#pragma mark - 代码分支---主项目cellforrow and didselect
//#ifdef Main
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if([getUIStyle() isEqualToString:STYLE0]){
        [self seleStyle0CCell:indexPath];
    }else{
        
        
        [self seleStyle1CCell:indexPath];
    }
    
    return;

}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
